package io.gitee.geminidev.bot.util;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author gemini
 * @Date 2023/4/19 22:32
 * @description:
 */
public class GroupedSet<K, V> {

    Map<K, LinkedHashSet<V>> map = new LinkedHashMap<>();

    public boolean put(K key, V value){
        LinkedHashSet<V> hashSet;
        if(map.containsKey(key)){
            hashSet = map.get(key);
        } else {
            hashSet = new LinkedHashSet<>();
            map.put(key, hashSet);
        }
        return hashSet.add(value);
    }

    public LinkedHashSet<V> getGroup(K group){
        if(!map.containsKey(group)){
            return null;
        }
        return map.get(group);
    }

}
